package main

import (
	"fmt"
	"reflect"
)

type student struct {
	Name   string
	Number int
	Height uint
	Weight float64
}

func (s student) Info() {
	fmt.Printf("Name:\t%s\n", s.Name)
	fmt.Printf("Number:\t%03d\n", s.Number)
	fmt.Printf("Height:\t%d cm\n", s.Height)
	fmt.Printf("Weight:\t%.2f kg\n", s.Weight)
}

func (s *student) SetHeightWeight(h uint, w float64) {
	s.Height = h
	s.Weight = w
}

func main() {
	s1 := student{"Jimmy", 1, 170, 65.5}
	stp1 := reflect.ValueOf(&s1)
	f1 := stp1.MethodByName("SetHeightWeight")
	if f1.Kind() != reflect.Invalid {
		args := []reflect.Value{
			reflect.ValueOf(uint(172)),  // 直接填数值，会被认作是int类型，需要转成uint
			reflect.ValueOf(66.6),       // 浮点数不用转，默认就认作浮点数
		}
		f1.Call(args)
	}
	f2 := stp1.MethodByName("Info")
	if f2.Kind() != reflect.Invalid {
		f2.Call(nil)  // 也可以传一个空切片 []reflect.Value{}
	}
}
